
var moveFunctions = (function() {
    //元素向右移动
    function moveRight(curEle){
        
        var winWidth = document.documentElement.clientWidth;
        var boxWidth = window.getComputedStyle(curEle,null).width;
        var curLeft = parseFloat(window.getComputedStyle(curEle,null).left);
        var target = winWidth - parseFloat(boxWidth);
        var step = (target-curLeft)/2000 * 10;
        
        
        
        
        var timer = window.setInterval(function(){
            curLeft += step;
            if(parseFloat(window.getComputedStyle(curEle,null).left) >= target){
                curEle.style.left = target + 'px';
                window.clearInterval(timer);
                return;
            }
            
            curEle.style.left = curLeft + 'px';
        },10);
    }
    
    //元素向左移动
    function moveLeft(curEle){
        
        var winWidth = document.documentElement.clientWidth;
        var boxWidth = window.getComputedStyle(curEle,null).width;
        var curLeft = parseFloat(window.getComputedStyle(curEle,null).left);
        var step = (curLeft/2000) * 10;
        
        
        console.log(winWidth,boxWidth);
        
        var timer = window.setInterval(function(){
            if(parseFloat(window.getComputedStyle(curEle,null).left) <= 0){
                window.clearInterval(timer);
                return;
            }
            curLeft -= step;
            curEle.style.left = curLeft + 'px';
        },10);
        
          
    }
    
    
    
    
    
    //增加时间的方式
    function move1(curEle){
        var winWidth = document.documentElement.clientWidth;
        var boxWidth = window.getComputedStyle(box,null).width;
        console.log(winWidth,boxWidth);
        var time = null;
        var duration = 2000;//总时间2000毫秒
        var distance = winWidth - parseFloat(boxWidth);//总距离
        
       var timer =  window.setInterval(function(){
            time = time || 0;
            time += 10;
            if(time >= duration){
                window.clearInterval(timer);
                return;
            }
            var position = (time / duration) * distance;
            curEle.style.left = position + 'px';
        },10);
    }

    //左右移动方式
    function move(curEle,target){//目标位置
        window.clearInterval(timer);
        var duration = 2000;//总时间2000毫秒
        var curPosition = parseFloat(window.getComputedStyle(curEle,null).left);
        console.log(curPosition);
        if(target >= curPosition){
            var step = (target - curPosition)/duration * 10;//步长
            console.log(step);
             timer = window.setInterval(function(){
                curPosition += step;
                if(curPosition >= target){
                    curEle.style.left = target + 'px';
                    window.clearInterval(timer);
                    return;
                }
                curEle.style.left = curPosition + 'px';
                
            },10);
        }else{
            
            var step = (curPosition - target)/duration * 10;//步长
             timer = window.setInterval(function(){
                curPosition -= step;
                if(curPosition <= target){
                    curEle.style.left = target + 'px';
                    window.clearInterval(timer);
                    return;
                }
                curEle.style.left = curPosition + 'px';
                
            },10);
        }
    }

    //上下移动方式
    function move2(curEle,target){//目标位置
        window.clearInterval(timer);
        var duration = 2000;//总时间2000毫秒
        var curPosition = parseFloat(window.getComputedStyle(curEle,null).top);
        console.log(curPosition);
        if(target >= curPosition){
            var step = (target - curPosition)/duration * 10;//步长
            console.log(step);
             timer = window.setInterval(function(){
                curPosition += step;
                if(curPosition >= target){
                    curEle.style.top = target + 'px';
                    window.clearInterval(timer);
                    return;
                }
                curEle.style.top = curPosition + 'px';
                
            },10);
        }else{
            
            var step = (curPosition - target)/duration * 10;//步长
             timer = window.setInterval(function(){
                curPosition -= step;
                if(curPosition <= target){
                    curEle.style.top = target + 'px';
                    window.clearInterval(timer);
                    return;
                }
                curEle.style.top = curPosition + 'px';
                
            },10);
        }
    }
    return {
        mLeft:moveLeft,
        mRight:moveRight,
        move:move,
        move1:move1,
        move2:move2
    }
})()



